package com.venue.hjt.venueclass.utlis;


import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.util.Log;

import com.venue.hjt.venueclass.R;
import com.venue.hjt.venueclass.bean.API;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

/**
 * Created by Administrator on 2017/5/25.
 * 网络请求
 */

public class OkhttPost {
	public static void Okpost(String url, Map<String,String> map, int id, final Callback ca){
		OkHttpUtils.post().url(url).addHeader("Content-Type","application/x-www-form-urlencoded").params(map).id(id).build().execute(new StringCallback() {
			@Override
			public void onError(Call call, Exception e, int id) {
				ca.onError(call,e,id);
			}

			@Override
			public void onResponse(String response, int id) {
				ca.onResponse(response,id);
			}
		});
	}
    public static void Okget(String url, int id, final Callback ca){
		OkHttpUtils.get().url(url).id(id).build().execute(new StringCallback() {
			@Override
			public void onError(Call call, Exception e, int id) {
				ca.onError(call,e,id);

			}
			@Override
			public void onResponse(String response, int id) {
				ca.onResponse(response,id);
			}
		});
	}
	public static void OkFile(String url, final FileCallBack callBack){
		OkHttpUtils.
				get()
				.url(url)
				.build()
				.execute(new com.zhy.http.okhttp.callback.FileCallBack(Environment.getExternalStorageDirectory().getPath()+"/Class", "Class.apk") {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        callBack.onError(call,e,id);
                    }

                    @Override
                    public void onResponse(File response, int id) {
                        callBack.onResponse(response,id);
                    }
                });

	}
	public static void Deleteget(String url, final String Nid , int id, final DeteleCallback ca, final String did, final String  name, final String time, final String content){
		OkHttpUtils.get().url(url).id(id).build().execute(new StringCallback() {
			@Override
			public void onError(Call call, Exception e, int id) {
				ca.onError(call,e,Nid,id,did,name,time,content);

			}

			@Override
			public void onResponse(String response, int id) {
				ca.onResponse(response,Nid,id,did,name,time,content);
			}
		});
	}


	public interface DeteleCallback {

		void onError(Call call, Exception e, String nid, int id, String did, String name, String time, String content);

		void onResponse(String response, String nid, int id, String did, String name, String time, String content);


	}

    public interface Callback {

         void onError(Call call, Exception e, int id);

         void onResponse(String response, int id);


    }
	public interface FileCallBack{
		void onError(Call call, Exception e, int id);
        void onResponse(File response, int id);
	}
	public static void Card(String img, String booking_id, String signin_id, String signin_time, final Callback callback) {
        try {
                Map<String, String> map = new HashMap<>();

                map.put("sno", Constant.SNO);
                map.put("booking_id", booking_id);
                map.put("signin_id", signin_id);
                map.put("card_no", "");
                map.put("signin_time", signin_time);
                map.put("image", img);
//                map.put("SourceStartTime", "-1");
//                map.put("ContrastImg", Url);
//			http://129.1.2.243/hjtgrow/public/boardApi/venue/booking/signin?sno=98&booking_id=1&signin_id=8888&card_no=111111&signin_time=2018-03-16%2010:28&img=%E2%80%9C%E2%80%9D

                OkHttpUtils.post().url(API.CARD).params(map).build().execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        callback.onError(call, e, id);
                        Log.e("Date", "错误 " + e.getMessage());
                    }
                    @Override
                    public void onResponse(String response, int id) {
                        callback.onResponse(response, id);
                        Log.e("Date", response);
                    }
                });

        } catch (NullPointerException e) {
			Log.e("Date", "错误 " + e.toString());
        }
    }

}
